/*
 * @Author: fisher
 * @Date: 2022-10-25 17:14:33
 * @LastEditTime: 2022-12-21 21:00:36
 * @LastEditors: your name
 * @Description:
 * @FilePath: /vite-vue-ts-h5/src/utils/jsbridge/defaultOptions.ts
 * 可以输入预定的版权声明、个性签名、空行等
 */
import { Api, globalize } from 'js-bridge-adapter'
interface Obj {
  [key: string]: any
}
export default function (api: Function): Obj {
  return {
    // 调起获取token
    getToken: new Api({
      getRunner() {
        return (data: Obj) => {
          if (typeof data.callbackName === 'function') {
            globalize(data.callbackName, {
              name: 'getTokenCallback'
            })
            data.callbackName = 'getTokenCallback'
          }
          api('al_jsGetToken')([JSON.stringify(data)])
        }
      }
    }),
    // 获取用户信息
    getAppInfo: new Api({
      getRunner() {
        return (data: Obj) => {
          if (typeof data.callbackName === 'function') {
            globalize(data.callbackName, {
              name: 'getBasicInfoCallback'
            })
            data.callbackName = 'getBasicInfoCallback'
          }
          api('al_jsGetAppInfo')([JSON.stringify(data)])
        }
      }
    }),
    // 打开webview
    createWebview: new Api({
      getRunner() {
        return (data: Obj) => {
          api('al_jsCreateWebview')([JSON.stringify(data)])
        }
      }
    }),
    // 关闭webview
    closeWebview: new Api({
      getRunner() {
        return (data: Obj) => {
          api('al_jsCloseCurrentWebview')([JSON.stringify(data)])
        }
      }
    }),
    // 跳我的保单列表
    goMyPolicy: new Api({
      getRunner() {
        return (data: Obj) => {
          api('al_jsGoMyPolicy')([JSON.stringify(data)])
        }
      }
    })
  }
}
